﻿//        Another Demo from Andy L. & MissedMemo.com
// Borrow whatever code seems useful - just don't try to hold
// me responsible for any ill effects. My demos sometimes use
// licensed images which CANNOT legally be copied and reused.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;


namespace MissedMemo.MeatAndCheeseDisc.OrderEntry
{
    public partial class viewOrderEditPanel : UserControl
    {
        public viewOrderEditPanel()
        {
            InitializeComponent();
        }


        internal void Open( Double containerHeight )
        {
            // Reset active tab each time view is opened
            tabControl.SelectedIndex = 0;

            DoubleAnimation b = new DoubleAnimation( containerHeight, TimeSpan.Parse( "0:0:0.25" ) );

            b.FillBehavior = FillBehavior.Stop;  // Required, to enable height set to NaN

            // Setting height to NaN enables automatic adjustment to dynamic resizing of containing window
            b.Completed += ( sender, e ) => { Height = Double.NaN; };

            BeginAnimation( UserControl.HeightProperty, b );
        }


        private void Close()
        {
            DoubleAnimation b = new DoubleAnimation( ActualHeight, 0, TimeSpan.Parse( "0:0:0.25" ) );

            BeginAnimation( UserControl.HeightProperty, b );
        }


        private void OnDone( object sender, RoutedEventArgs e )
        {
            Close();
        }
    }
}
